package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.SysTeacherClass;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysContractLabel;
import com.ruoyi.system.service.ISysContractLabelService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 合同明细Controller
 *
 * @author ruoyi
 * @date 2025-06-17
 */
@RestController
@RequestMapping("/system/contract/label")
public class SysContractLabelController extends BaseController
{
    @Autowired
    private ISysContractLabelService sysContractLabelService;

    /**
     * 查询合同明细列表
     */
    //@PreAuthorize("@ss.hasPermi('system:label:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody SysContractLabel sysContractLabel)
    {
        startPage();
        List<SysContractLabel> list = sysContractLabelService.selectSysContractLabelList(sysContractLabel);
        return getDataTable(list);
    }

    /**
     * 根据教师主键查询合同明细
     * @param sysTeacherClass
     * @return
     */
    @GetMapping("/selectContractLabelLIstByTeacherId")
    public TableDataInfo selectContractLabelLIstByTeacherId(SysTeacherClass sysTeacherClass){
        startPage();
        List<SysContractLabel> sysContractLabelList = sysContractLabelService.selectContractLabelLIstByTeacherId(sysTeacherClass);
        return getDataTable(sysContractLabelList);
    }

    /**
     * 导出合同明细列表
     */
    @PreAuthorize("@ss.hasPermi('system:label:export')")
    @Log(title = "合同明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysContractLabel sysContractLabel)
    {
        List<SysContractLabel> list = sysContractLabelService.selectSysContractLabelList(sysContractLabel);
        ExcelUtil<SysContractLabel> util = new ExcelUtil<SysContractLabel>(SysContractLabel.class);
        util.exportExcel(response, list, "合同明细数据");
    }

    /**
     * 获取合同明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:label:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysContractLabelService.selectSysContractLabelById(id));
    }

    /**
     * 新增合同明细
     */
    //@PreAuthorize("@ss.hasPermi('system:label:add')")
    @Log(title = "合同明细", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SysContractLabel sysContractLabel)
    {
        return toAjax(sysContractLabelService.insertSysContractLabel(sysContractLabel));
    }

    /**
     * 修改合同明细
     */
    @PreAuthorize("@ss.hasPermi('system:label:edit')")
    @Log(title = "合同明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysContractLabel sysContractLabel)
    {
        return toAjax(sysContractLabelService.updateSysContractLabel(sysContractLabel));
    }

    /**
     * 删除合同明细
     */
    //@PreAuthorize("@ss.hasPermi('system:label:remove')")
    @Log(title = "合同明细删除方法", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(sysContractLabelService.deleteSysContractLabelById(id));
    }
}